package es.juanc.io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class EncodingTest {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		
		InputStreamReader reader1 = new InputStreamReader( new FileInputStream( "String.txt" ) );
		System.out.println( "Encoding del entorno: " + reader1.getEncoding() );
		BufferedReader br1 = new BufferedReader( reader1 );
		String line1;
		while( (line1=br1.readLine()) != null ) {
			System.out.println( "  " + line1 );
		}
		reader1.close();
		
		InputStreamReader reader2 = new InputStreamReader( new FileInputStream( "String.txt" ), "UTF-8" );
		System.out.println( "Encoding asignado: " + reader2.getEncoding() );
		BufferedReader br2 = new BufferedReader( reader2 );
		String line2;
		while( (line2=br2.readLine()) != null ) {
			System.out.println( "  " + line2 );
		}
		reader2.close();
		
		OutputStreamWriter osw1 = new OutputStreamWriter( new FileOutputStream( "conWindows.txt" ) );
		System.out.println( "Encoding asignado: " + osw1.getEncoding() );
		Writer writer1 = new BufferedWriter( osw1 );		
		writer1.write( "esto es una prueba" );
		writer1.flush();
		writer1.close();
		
		OutputStreamWriter osw2 = new OutputStreamWriter( new FileOutputStream( "conUnix.txt" ), "UTF-8" );
		System.out.println( "Encoding asignado: " + osw2.getEncoding() );
		Writer writer2 = new BufferedWriter( osw2 );
		writer2.write( "esto es una prueba" );
		writer2.flush();
		writer2.close();
	}
}